<?php include '../common/session.php' ?>
<?php include '../common/header.php' ?>
<?php
	if( $_SESSION['userType'] == 'less' ){
		$url = $_SERVER['HTTP_REFERER'];
		header('location:'.$url);
	}
	$active = $_GET['active'];
	$id = $_GET['id'];
	
	if( $active == 'edit' ){
		include "../common/connect.php";
		$result = mysql_query("SELECT * FROM new WHERE id='".$id."'");
		mysql_close($con);
		$row = mysql_fetch_array($result);
		if( !is_array($row) ){
			$url = $_SERVER['HTTP_REFERER'];
			header('location:'.$url);
		}
	}
?>
<body>
<?php include "menus.php" ?>
<div id="main">
	<h2><?php if( $active == 'edit' ){ ?>编辑<?php }else{ ?>添加<?php } ?>文章<a href="newAdmin.php">[返回]</a></h2>
	<div class="addArt">
		<form action="addArt.php?id=<?php echo $id ?>" method="post">
			<label>
				<b>标题：</b>
				<input name="title" type="text" value="<?php if( $active == 'edit' ){ echo $row['title']; } ?>" />
			</label>
			<label>
				<b>分类：</b>
				<select name="type">
					<option <?php if( $active == 'edit' && $row['type'] == 'default' ){ ?> selected="selected" <?php } ?> value="default">默认分类</option>
					<option <?php if( $active == 'edit' && $row['type'] == 'life' ){ ?> selected="selected" <?php } ?> value="life">生活品味</option>
					<option <?php if( $active == 'edit' && $row['type'] == 'technology' ){ ?> selected="selected" <?php } ?> value="technology">技术相关</option>
				</select>
			</label>
			<label class="clearfix">
				<b>内容：</b>
				<div class="editor"><textarea name="article" id="DirEditor"><?php if( $active == 'edit' ){ echo $row['content']; } ?></textarea></div>
			</label>
			<label>
				<input type="submit" class="sub" value="<?php if( $active == 'edit' ){ ?>修 改<?php }else{ ?>提 交<?php } ?>" />
			</label>
		</form>
	</div>
</div>
<script src="../ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="../ueditor/ueditor.all.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
	var editor = new UE.ui.Editor();
	editor.render("DirEditor");
});
</script>
</body>
</html>